<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-赠品管理">
</@frame.head>
<link rel="stylesheet" type="text/css" href="${contextPath}/resources/css/search_table.css" />
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 后台管理中心 <span class="c-gray en">&gt;</span> 促销管理 <span class="c-gray en">&gt;</span> 赠品管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
   <div class="text-c">
    <form action="${contextPath}/present/query_list" method="post" name="search_form" id="search_form">
       <input type="hidden" name="page" value="${pagination.pageNo}"  id="page" />  
       <table class="table search_table" >
          <tr>  
           <td>赠品编号：</td>
           <td><input type="text" class="input-text  radius"  placeholder="请输入赠品编号" name="presentNo" id="presentNo" value="${presentQo.presentNo}" onkeyup='this.value=this.value.replace(/\D/g,"")'>
           <td>赠品名称：</td>
           <td><input type="text" class="input-text  radius"  placeholder="请输入赠品名称" name="presentName" id="presentName" value="${presentQo.presentName}" >
          </td>   
           <td>商户名称：</td>
           <td>
           
           <span class="select-box radius">
           <select class="select"  name="merchantQo.id" id="merchantQoId">
           <option value>请选择</option>
             <#list merchantNewList as list>  
                 <option value="${list.id?c}" <#if list.id==presentQo.merchantQo.id>selected="selected"</#if>>${list.mercName}</option>
             </#list>
           </select>
           </span>
           </td>   
         </tr>
         <tr>
           <td>编辑时间：</td>
           <td><input  type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'endDate\')}',readOnly: true })" id="startDate" 
               value='${(presentQo.editDateStart?string("yyyy-MM-dd"))!}' name="editDateStart"  class="input-text Wdate" style="width:45%;">
                                                至
               <input  type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'startDate\')}',readOnly: true })" id="endDate" 
               value='${(presentQo.editDateEnd?string("yyyy-MM-dd"))!}' name="editDateEnd"    class="input-text Wdate" style="width:45%;">
           </td>
           <td>审核状态：</td>
           <td>
           <span class="select-box radius">
           <select class="select" name="authStatus" id="authStatus">
           <option  value>请选择
		   </option>
           <option value="0" <#if presentQo.authStatus==0>selected = "selected"</#if> >未审核
		   </option>
		   <option value="1"  <#if presentQo.authStatus==1>selected = "selected"</#if>>审核通过
		   </option>
		   <option value="2"  <#if presentQo.authStatus==2>selected = "selected"</#if>>审核未通过
		   </option>
           </select>
           </span>
          </td>   
           <td>使用状态：</td>
           <td>           
           <span class="select-box radius">
           <select class="select"  name="status" id="status">
           <option  value>请选择
		   </option>
		   <option value="1"  <#if presentQo.status==1>selected = "selected"</#if> >启用
		   </option>
		   <option value="2"  <#if presentQo.status==2>selected = "selected"</#if> >禁用
		   </option>
           </select>
           </span>
          </td> 
         </tr>
         <tr>
           <td colspan="6">
              <input class="btn btn-success radius" type="button" onclick="search();" value="搜索" />
              <input class="btn btn-success radius" type="button" onclick="toIsEmpty();"  value="重置" />
              <input class="btn btn-success radius" type="button" onclick="search();" value="刷新" />
               <input class="btn btn-success radius" type="button" onclick="excel();" value="导出" />
           </td>
         </tr>
      </table>
     </form>
    </div>

    <div class="cl pd-5 bg-1 bk-gray mt-20"> 
    <span class="l">
    <a href="${contextPath}/present/to_add_present"  class="btn btn-primary radius">发布赠品</a> 
    </span>
    <span class="r">共有数据：<strong>${pagination.totalCount}</strong> 条</span> </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr  class="text-c">
           
            <th >赠品编号</th>
            <th >赠品名称</th>
            <th >剩余库存</th>
            <th >所属供应商</th>
            <th >编辑时间</th>
            <th >审核状态</th>
            <th >使用状态</th>
            <th >操作</th>
        </tr>
        </thead>
        <tbody >
         <#list pagination.list as list> 
         <tr  class="text-c">
            
            <td>${list.id}</td>
            <td>${list.name}</td>
            <td>${list.presentStock-list.presentSaleStock}</td>
            <td>${list.merchant.mercName}</td>
            <td>${(list.editDate?string("yyyy-MM-dd HH:mm:ss"))!}</td>
            <td>
            <#if list.authStatus==0>未审核
            <#elseif list.authStatus==1>审核通过
            <#else>审核不通过
            </#if>
			</td>
            <td>
            <#if list.status==1>启用
            <#else>禁用
            </#if>
            </td>
            <td>
            <#if list.status==2&&list.authStatus==0><a href="javascript:;"  onclick="audit_present('${list.id?c}');">审核</a>
            </#if>
            <#if list.status==2&&list.authStatus==1><a href="javascript:;"  onclick="openPresent('${list.id?c}');">启用</a>
            </#if>
           <#if list.status==1&&list.authStatus==1><a href="javascript:;"  onclick="openPresent('${list.id?c}');">禁用</a>
            </#if>
			<a href="javascript:;"  onclick="look_present('${list.id?c}');">查看</a>
			<a href="javascript:;"  onclick="edit_present('${list.id?c}');">编辑</a>
            </td>
         </tr>
         </#list>
        </tbody>
    </table>
    <div id="div_page" style="padding-top: 10px;float: right"></div>
</div>
</div>
<@frame.end "default">
</@frame.end>
</html>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/laypage/laypage.js"></script>
<script type="text/javascript">
var path="${contextPath}";
laypage({
    cont: 'div_page',//容器。值支持id名、原生dom对象，jquery对象。
    pages: ${pagination.totalPage},//通过后台拿到的总页数
    curr:  ${pagination.pageNo} || 1, //当前页
	skip: true, //是否开启跳页
	first: 1, //将首页显示为数字1,。若不显示，设置false即可
	last: ${pagination.totalPage}, //将尾页显示为总页数。若不显示，设置false即可
    jump: function(obj , first){//触发分页后的回调
        if(!first){ //点击跳页触发函数;当前页为obj.curr
            $("#page").val(obj.curr);
            $("#search_form").submit();
        }
    }
});
function search() {
      
	$("#page").val("1");
	$("#search_form").submit();
}
function excel(){
	 var form_path= $(search_form).attr("action");
    $(search_form).attr("action",path+"/present/present_excel").submit(); 
    $(search_form).attr("action",form_path);
}
/*查看*/
 function look_present(id){
	  var url=path+"/present/look_present?presentId="+id;
	  if(url!=""){
	      var index = layer.open({
	            type: 2,
	            title: '查看赠品',
	            scrollbar: false,
	            content: url,
	            area: ['1000px', '600px']
	        });
	    }
}
 /*审核*/
 function audit_present(id){
	  var url=path+"/present/to_audit_present?presentId="+id;
	  if(url!=""){
	      var index = layer.open({
	            type: 2,
	            title: '审核赠品',
	            scrollbar: false,
	            content: url,
	            area: ['1000px', '600px']
	        });
	    }
}
 /*编辑*/
 function edit_present(id){
	  var url=path+"/present/to_edit_present?presentId="+id;
	  if(url!=""){
	      var index = layer.open({
	            type: 2,
	            title: '编辑赠品',
	            scrollbar: false,
	            content: url,
	            area: ['1000px', '600px']
	        });
	    }
}
 function callback2(flag, message) {
		layer.closeAll('loading');
		if (flag == true) {
			layer.msg('修改成功!',{icon:1,time:1000},function(){
				window.location = path + "/present/query_list";
			});
			
		} else {
			layer.alert(message);
		}
	}
 function openPresent(id){
	 
	 $.ajax({
			url : path+"/present/open_present",
			cache : false,
			type : 'post',
			dataType : 'text',
			data:{"presentId":id},
			error : function() {
				layer.alert("操作失败！");
	       },
			success : function(data) {
			    if(data == "success"){
				    layer.msg('操作成功!',{icon:1,time:1000},function(){
				    	window.location.reload();
				    });
			   }else if(data == "fail"){
				layer.alert("操作失败！");
			   } else {
				   layer.alert(data);
			   }
			},
			complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
			}
		  })	
	 
 }
 //重置
 function toIsEmpty() {
		$("#presentNo").val("");
		$("#presentName").val("");
		$("#merchantQoId").val("");
		$("#startDate").val("");
		$("#endDate").val("");
		$("#authStatus").val("");
		$("#status").val("");



	}
</script>